import java.util.Random;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/3/22
 * \* Time: 11:49
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */

public class Demo8 {
    private static int sum2 = 0;
    private static int sum1 = 0;
    public static void main(String[] args) {

        int [] array = new int[1_0000_000];
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(100);
        }

        long beg = System.currentTimeMillis();
        Thread t1 = new Thread(()->{

            for (int i = 0; i < array.length; i++) {
                if(array[i] % 2 == 0){
                    sum1 += array[i];
                }
            }
        });
        t1.start();

        Thread t2 = new Thread(()->{

            for (int i = 0; i < array.length; i++) {
                if(array[i] % 2 !=0){
                   sum2 += array[i];
                }
            }
        });
        t2.start();
        int sum = sum1+sum2;
        long end = System.currentTimeMillis();
        System.out.println("消耗时间："+ (end - beg) +"ms");
    }
}
